﻿#include "GUIRectangularDialog.h"
#include "ui_GUIRectangularDialog.h"

#include "PickDataProvider/GUIPickInfo.h"
#include "PickDataProvider/PickedData.h"
#include "PickDataProvider/PickedDataProvider.h"
#include "OperatorsInterface/GraphEventOperator.h"
#include "OperatorsInterface/TreeEventOperator.h"

#include "FITK_Kernel/FITKCore/FITKOperatorRepo.h"
#include "FITK_Kernel/FITKCore/FITKDataRepo.h"
#include "FITK_Kernel/FITKAppFramework/FITKAppFramework.h"
#include "FITK_Kernel/FITKAppFramework/FITKGlobalData.h"
#include "FITK_Component/FITKAcousticsModel/FITKAcousticsDiscModel.h"
#include "FITK_Component/FITKAcousticsModel/FITKAcousticsSEAModel.h"
#include "FITK_Component/FITKAcousticsModel/FITKAbstractSEASubSys.h"
#include "FITK_Component/FITKAcousticsModel/FITKSEAAbstractJunction.h"
#include "FITK_Component/FITKAcousticsModel/FITKAcousticsFEModel.h"
#include "FITK_Component/FITKAcousticsModel/FITKAbstractFESubSys.h"
#include "FITK_Component/FITKAcousticsModel/FITKAcousticsFEFace.h"
#include "FITK_Component/FITKAcousticsModel/FITKAcousticsSensors.h"
#include "FITK_Component/FITKAcousticsModel/FITKAcousticsGeometryData.h"
#include "FITK_Component/FITKAcousticsPhysics/FITKAcousticsPhysics.h"
#include "FITK_Component/FITKAcousticsPhysics/FITKAcousticsLoadManager.h"
#include "FITK_Interface/FITKInterfaceGeometry/FITKAbsVirtualTopo.h"
#include "FITK_Interface/FITKInterfaceGeometry/FITKAbsVirtualTopoMapper.h"

#include "FITK_Kernel/FITKCore/FITKActionOperator.h"
#include "FITK_Interface/FITKInterfaceGeometry/FITKAbsGeomTools.h"
#include "FITK_Interface/FITKInterfaceGeometry/FITKGeoInterfaceFactory.h"
#include "PickDataProvider/PickedData.h"
#include "PickDataProvider/PickedDataProvider.h"

#include "FITK_Component/FITKAcousticsModel/FITKAcousticsSEAModel.h"
#include "FITK_Kernel/FITKCore/FITKVec3D.h"
#include "FITK_Component/FITKAcousticsModel/FITKAcousticsDiscNodeList.h"
#include "FITK_Interface/FITKInterfaceModel/FITKElementList.h"
#include "FITK_Component/FITKAcousticsModel/FITKAbstractSEAFace.h"
#include "FITK_Component/FITKAcousticsModel/FITKAcousticsTriangles.h"
#include "FITK_Component/FITKAcousticsModel/FITKAbstractSEASubSysWithNodes.h"
#include "FITK_Component/FITKAcousticsModel/FITKSEASubSysBeam.h"
#include "FITK_Component/FITKAcousticsModel/FITKSEAFlatCurvedFace.h"
#include "FITK_Component/FITKAcousticsModel/FITKSEASubSysShellPlate.h"
#include "FITK_Interface/FITKInterfaceModel/FITKElementList.h"
#include "FITK_Interface/FITKInterfaceModel/FITKAbstractElement.h"
#include "FITK_Component/FITKAcousticsModel/FITKSEASubSysShellCurved.h"
#include "FITK_Interface/FITKInterfaceModel/FITKElementFactory.h"
#include "FITK_Kernel/FITKCore/FITKVec3D.h"
#include "FITK_Kernel/FITKCore/FITKVec3DAlg.h"

#include <cmath>
#include <QSet>
#include <QMessageBox>

#define _SEA_SUBSYSTEM_ 0
#define _FE_SUBSYSTEM_ 1
#define _SEA_SHELL_ 2
#define _SEA_BEAM_ 3
#define _LINE_SPACING_ 4
#define _LINE_LENGTH_ 5
#define _LINT_SPCAING_LENGTH_ 6
#define _ARCED_SPACING_ 4
#define _ARCED_LENGTH_ 5
#define _ARCED_SPCAING_LENGTH_ 6

namespace GUI
{
    GUIRectangularDialog::GUIRectangularDialog(Core::FITKActionOperator* oper, QWidget* parent /*= nullptr*/) :
        GUIDialogBase(FITKAPP->getGlobalData()->getMainWindow()) ,_oper(oper)
    {
        _ui = new Ui::GUIRectangularDialog();
        _ui->setupUi(this);
        // 设置对话框关闭时自动删除
        setAttribute(Qt::WA_DeleteOnClose);
        //去掉问号
        Qt::WindowFlags flags = windowFlags();
        flags &= ~Qt::WindowContextHelpButtonHint;
        setWindowFlags(flags);

        this->init();
    }

    GUIRectangularDialog::~GUIRectangularDialog()
    {
        if (_ui) {
            delete _ui;
            _ui = nullptr;
        }
        //所有的类在执行完毕后，将清空对3维的操作
        GraphData::PickedDataProvider* provider = GraphData::PickedDataProvider::getInstance();
        if (provider == nullptr)return;
        provider->clearPickedData();//清空拾取数据
        //拾取对象 关闭
        //拾取方式 空
        GUI::GUIPickInfoStru pickInfo = GUI::GUIPickInfo::GetPickInfo();
        pickInfo._pickObjType = GUI::GUIPickInfo::PickObjType(GUI::GUIPickInfo::POBJNone);
        pickInfo._pickMethod = GUI::GUIPickInfo::PickMethod(GUI::GUIPickInfo::PickMethod::PMNone);
        //设置拾取方式
        GUI::GUIPickInfo::SetPickInfo(pickInfo);
    }

    void GUIRectangularDialog::init()
    {
        // 设置对话框标题
        setWindowTitle(tr("Rectangular Pattern"));
        // 向模型选择下拉框添加选项
        _ui->comboBox_Model->addItem("Plate", _SEA_SHELL_);
        _ui->comboBox_Model->addItem("Beam", _SEA_BEAM_);
        // 向对象选择下拉框添加选项
        _ui->comboBox_Object->addItem("SEAsubsystem", _SEA_SUBSYSTEM_);
        _ui->comboBox_Object->addItem("FEsubsystem", _FE_SUBSYSTEM_);

        _ui->tabWidget->setTabText(0, "Linear");
        _ui->tabWidget->setTabText(1, "Arced");

        _ui->comboBox_Parameters->addItem("Instances & Spacing", _LINE_SPACING_);
        _ui->comboBox_Parameters->addItem("Instances & Length", _LINE_LENGTH_);
        _ui->comboBox_Parameters->addItem("Spacing & Length", _LINT_SPCAING_LENGTH_);

        _ui->comboBox_Parameters_2->addItem("Instances & Spacing", _ARCED_SPACING_);
        _ui->comboBox_Parameters_2->addItem("Instances & Length", _ARCED_LENGTH_);
        _ui->comboBox_Parameters_2->addItem("Spacing & Length", _ARCED_SPCAING_LENGTH_);

        _ui->spinBox_Instances->setValue(2);
        _ui->spinBox_Instances->setMinimum(2);
        _ui->spinBox_Instances_2->setValue(2);
        _ui->spinBox_Instances_2->setMinimum(2);

        _ui->lineEdit_Length->setText("20");
        _ui->lineEdit_Angel->setText("20");
        _ui->lineEdit_Spacing->setText("20");
        _ui->lineEdit_Spacing_2->setText("20");
    }

    void GUIRectangularDialog::pickFinishedOper()
    {
        // 获取拾取数据提供者实例
        GraphData::PickedDataProvider* provider = GraphData::PickedDataProvider::getInstance();
        if (provider == nullptr) return;
        // 断开拾取完成信号的连接
        disconnect(provider, SIGNAL(sig_pickedOver()), this, SLOT(slotPickOverEvent()));

        if (_flag == 1 || _flag == 2 || _flag == 3 || _flag == 4)
        {
            // 获取拾取列表
            QList<GraphData::PickedData*> pickList = provider->getPickedList();
            QList<Acoustics::FITKAbstractSEASubSysWithNodes::SubSysNode> nodes;
            for (GraphData::PickedData* pickData : pickList)
            {
                if (!pickData) continue;
                // 获取拾取数据的类型
                GraphData::PickedDataType pickType = pickData->getPickedDataType();
                if (GraphData::PickedDataType::DiscNodePick == pickType)
                    // 如果是离散节点拾取，添加到节点列表
                    nodes.append(pickData->getPickedDiscNodes());
            }
            // 如果离散模型为空，返回
            if (_DiscModel == nullptr) return;
            // 获取离散节点列表
            Acoustics::FITKAcousticsDiscNodeList* nodelist = _DiscModel->getNodes();
            if (nodelist == nullptr) return;
            if (_flag == 1)
            {
                _fourPointID[0] = nodes[0]._id;
                // 根据ID获取节点
                Core::FITKNode* node = nodelist->getNodeByID(_fourPointID[0]);
                if (node == nullptr) return;
                _ui->Point_lineEditX->setText(QString::number(node->x()));
                _ui->Point_lineEditY->setText(QString::number(node->y()));
                _ui->Point_lineEditZ->setText(QString::number(node->z()));
            }
            else if (_flag == 2)
            {
                _fourPointID[1] = nodes[0]._id;
                // 根据ID获取节点
                Core::FITKNode* node = nodelist->getNodeByID(_fourPointID[1]);
                if (node == nullptr) return;
                _ui->Point_lineEditX_2->setText(QString::number(node->x()));
                _ui->Point_lineEditY_2->setText(QString::number(node->y()));
                _ui->Point_lineEditZ_2->setText(QString::number(node->z()));
            }
            else if (_flag == 3)
            {
                _fourPointID[2] = nodes[0]._id;
                // 根据ID获取节点
                Core::FITKNode* node = nodelist->getNodeByID(_fourPointID[2]);
                if (node == nullptr) return;
                _ui->Point_lineEditX_3->setText(QString::number(node->x()));
                _ui->Point_lineEditY_3->setText(QString::number(node->y()));
                _ui->Point_lineEditZ_3->setText(QString::number(node->z()));
            }
            else if (_flag == 4)
            {
                // 记录节点2的ID
                _fourPointID[3] = nodes[0]._id;
                // 根据ID获取节点
                Core::FITKNode* node = nodelist->getNodeByID(_fourPointID[3]);
                if (node == nullptr) return;
                // 将节点的坐标显示在文本框中
                _ui->Point_lineEditX_4->setText(QString::number(node->x()));
                _ui->Point_lineEditY_4->setText(QString::number(node->y()));
                _ui->Point_lineEditZ_4->setText(QString::number(node->z()));
            }
        }
        else if (_flag == 5)
        {
            QList<GraphData::PickedData*> pickList = provider->getPickedList();
            GraphData::PickedData* pickData = pickList.at(0);
            if (pickData == nullptr) return;
            // 记录拾取的模型对象的ID
            _modelObjID = pickData->getPickedDataObjId();
            _ui->label_Model->setText(_modelObjID == -1 ? tr("Picked (0)") : tr("Picked (1)"));
        }
    }

    void GUIRectangularDialog::rectangularLineSEAObj()
    {
        // 计算两点之间的x、y、z坐标差值
        double xV = _ui->Point_lineEditX_2->text().toDouble() - _ui->Point_lineEditX->text().toDouble();
        double yV = _ui->Point_lineEditY_2->text().toDouble() - _ui->Point_lineEditY->text().toDouble();
        double zV = _ui->Point_lineEditZ_2->text().toDouble() - _ui->Point_lineEditZ->text().toDouble();
        double length = sqrt(xV*xV + yV * yV + zV * zV);
        double spacer = 0;
        int objNum = 0;
        if (_ui->lineEdit_Spacing->isEnabled())
            spacer = _ui->lineEdit_Spacing->text().toDouble();
        else
            spacer = (_ui->lineEdit_Length->text().toDouble() / _ui->spinBox_Instances->text().toDouble()) / 1;
       
        if (_ui->spinBox_Instances->isEnabled())
            objNum = _ui->spinBox_Instances->text().toInt();
        else
            objNum = (_ui->lineEdit_Length->text().toDouble() / _ui->lineEdit_Spacing->text().toDouble()) / 1;

        if (_DiscModel == nullptr || _SEAModel == nullptr) return;
        // 获取离散模型的节点列表
        Acoustics::FITKAcousticsDiscNodeList* disNodeList = _DiscModel->getNodes();
        if (disNodeList == nullptr) return;
        // 获取SEA模型的子系统管理器
        Acoustics::FITKAcousticsSEASubSysManager* subsystemManager = _SEAModel->getSEASubSysManager();
        Acoustics::FITKSEAFaceManager* faceManager = _SEAModel->getSEAFaceManager();
        if (subsystemManager == nullptr || faceManager == nullptr) return;

        // 根据ID获取子系统对象
        Acoustics::FITKAbstractSEASubSysWithNodes* obj = dynamic_cast<Acoustics::FITKAbstractSEASubSysWithNodes*>(subsystemManager->getDataByID(_modelObjID));
        if (obj == nullptr) return;
        Acoustics::FITKAbstractSEAFace* face = obj->getFaceObj();
        if (face == nullptr) return;
        Acoustics::FITKAcousticsTriangles* triang = face->getTriangleMesh();
        if (triang == nullptr) return;
        //获取节点列表
        QList<int> noodeList = obj->getNodeIDs();
        QList<int> triNodeList = obj->getTriangleNodeIDs();
        QSet<int> allNodeList = noodeList.toSet().unite(triNodeList.toSet());

        for (int i=1;i< objNum;++i)
        {
            Acoustics::FITKAbstractSEASubSysWithNodes* newObj = nullptr;
            //判断数据对象类型
            if (obj->getSEASubSysType() == Acoustics::FITKAbstractSEASubSys::SEASubSysType::SEABeam)
                newObj = new Acoustics::FITKSEASubSysBeam;
            else if (obj->getSEASubSysType() == Acoustics::FITKAbstractSEASubSys::SEASubSysType::SEAFlatPlate)
                newObj = new Acoustics::FITKSEASubSysPlateShell;
            else if (obj->getSEASubSysType() == Acoustics::FITKAbstractSEASubSys::SEASubSysType::SEASinglyCurvedShell)
                newObj = new Acoustics::FITKSEASubSysSinglyCurvedShell;
            else if (obj->getSEASubSysType() == Acoustics::FITKAbstractSEASubSys::SEASubSysType::SEADoublyCurvedShell)
                newObj = new Acoustics::FITKSEASubSysDoublyCurvedShell;
            //拷贝数据对象
            if (newObj == nullptr) return;
            newObj->copy(obj);
            Acoustics::FITKAbstractSEAFace* newFace = newObj->getFaceObj();
            Acoustics::FITKAcousticsTriangles* newTriang = newFace->getTriangleMesh();
            subsystemManager->appendDataObj(newObj);
            //创建新节点做映射
            QHash<int, int> nodeIDs;
            for (int nodeID : allNodeList)
            {
                Core::FITKNode* node = disNodeList->getNodeByID(nodeID);
                if (node == nullptr) return;
                int newID = disNodeList->addNode(node->x() + (xV/length*spacer*i), node->y() + (yV/length*spacer*i), node->z() + (zV/length*spacer*i));
                nodeIDs.insert(node->getNodeID(), newID);
            }
            //通过映射存入新节点
            QList<Acoustics::FITKAbstractSEASubSysWithNodes::SubSysNode> subSysNodeList = face->getNodes();
            QList<Acoustics::FITKAbstractSEASubSysWithNodes::SubSysNode> newSubSysNodeList;
            for (Acoustics::FITKAbstractSEASubSysWithNodes::SubSysNode subSysNode : subSysNodeList)
            {
                Acoustics::FITKAbstractSEASubSysWithNodes::SubSysNode newSubSysNode;
                newSubSysNode._id = nodeIDs[subSysNode._id];
                newSubSysNode._type = subSysNode._type;
                newSubSysNodeList.append(newSubSysNode);
            }
            //通过映射存入新三角形网格
            for (int i = 0; i < triang->getElementCount(); ++i)
            {
                Interface::FITKAbstractElement* element = triang->getElementAt(i);
                if (element == nullptr) return;
                Interface::FITKModelEnum::FITKEleType type = element->getEleType();
                Interface::FITKAbstractElement* newElement = Interface::FITKElementFactory::createElement(type);

                for (int j = 0; j < element->getNodeCount(); ++j)
                    newElement->setNodeID(j, nodeIDs[element->getNodeID(j)]);
                newTriang->appendElement(newElement);
            }
            newFace->setNodes(newSubSysNodeList);
            if (!newObj->updateGeoProp()) return;
            _objIDList.append(newObj->getDataObjectID());
        }
    }
    void GUIRectangularDialog::rectangularArcedSEAObj()
    {
        // 创建起始点对象
        Core::FITKPoint* startPt = new Core::FITKPoint(_ui->Point_lineEditX_3->text().toDouble(), _ui->Point_lineEditY_3->text().toDouble(), _ui->Point_lineEditZ_3->text().toDouble());
        if (startPt == nullptr) return;
        // 创建结束点对象
        Core::FITKPoint* endPt = new Core::FITKPoint(_ui->Point_lineEditX_4->text().toDouble(), _ui->Point_lineEditY_4->text().toDouble(), _ui->Point_lineEditZ_4->text().toDouble());
        if (endPt == nullptr) return;
        // 创建旋转轴向量对象
        Core::FITKVec3D* axis = new Core::FITKVec3D(*endPt, *startPt);
        if (axis == nullptr) return;
        double spacer = 0;
        int objNum = 0;
        if (_ui->lineEdit_Spacing->isEnabled())
            spacer = _ui->lineEdit_Spacing_2->text().toDouble();
        else
            spacer = (_ui->lineEdit_Angel->text().toDouble() / _ui->spinBox_Instances_2->text().toDouble()) / 1;

        if (_ui->spinBox_Instances_2->isEnabled())
            objNum = _ui->spinBox_Instances_2->text().toInt();
        else
            objNum = (_ui->lineEdit_Angel->text().toDouble() / _ui->lineEdit_Spacing_2->text().toDouble()) / 1;

        if (_DiscModel == nullptr || _SEAModel == nullptr) return;
        // 获取离散模型的节点列表
        Acoustics::FITKAcousticsDiscNodeList* disNodeList = _DiscModel->getNodes();
        if (disNodeList == nullptr) return;
        // 获取SEA模型的子系统管理器
        Acoustics::FITKAcousticsSEASubSysManager* subsystemManager = _SEAModel->getSEASubSysManager();
        Acoustics::FITKSEAFaceManager* faceManager = _SEAModel->getSEAFaceManager();
        if (subsystemManager == nullptr || faceManager == nullptr) return;

        // 根据ID获取子系统对象
        Acoustics::FITKAbstractSEASubSysWithNodes* obj = dynamic_cast<Acoustics::FITKAbstractSEASubSysWithNodes*>(subsystemManager->getDataByID(_modelObjID));
        if (obj == nullptr) return;
        Acoustics::FITKAbstractSEAFace* face = obj->getFaceObj();
        if (face == nullptr) return;
        Acoustics::FITKAcousticsTriangles* triang = face->getTriangleMesh();
        if (triang == nullptr) return;
        //获取节点列表
        QList<int> noodeList = obj->getNodeIDs();
        QList<int> triNodeList = obj->getTriangleNodeIDs();
        QSet<int> allNodeList = noodeList.toSet().unite(triNodeList.toSet());

        for (int i = 1; i < objNum; ++i)
        {
            Acoustics::FITKAbstractSEASubSysWithNodes* newObj = nullptr;
            //判断数据对象类型
            if (obj->getSEASubSysType() == Acoustics::FITKAbstractSEASubSys::SEASubSysType::SEABeam)
                newObj = new Acoustics::FITKSEASubSysBeam;
            else if (obj->getSEASubSysType() == Acoustics::FITKAbstractSEASubSys::SEASubSysType::SEAFlatPlate)
                newObj = new Acoustics::FITKSEASubSysPlateShell;
            else if (obj->getSEASubSysType() == Acoustics::FITKAbstractSEASubSys::SEASubSysType::SEASinglyCurvedShell)
                newObj = new Acoustics::FITKSEASubSysSinglyCurvedShell;
            else if (obj->getSEASubSysType() == Acoustics::FITKAbstractSEASubSys::SEASubSysType::SEADoublyCurvedShell)
                newObj = new Acoustics::FITKSEASubSysDoublyCurvedShell;
            //拷贝数据对象
            if (newObj == nullptr) return;
            newObj->copy(obj);
            Acoustics::FITKAbstractSEAFace* newFace = newObj->getFaceObj();
            Acoustics::FITKAcousticsTriangles* newTriang = newFace->getTriangleMesh();
            subsystemManager->appendDataObj(newObj);
            //创建新节点做映射
            QHash<int, int> nodeIDs;
            for (int nodeID : allNodeList)
            {
                Core::FITKNode* node = disNodeList->getNodeByID(nodeID);
                if (node == nullptr) return;
                Core::FITKPoint* point = new Core::FITKPoint(node->x(), node->y(), node->z());
                if (point == nullptr) return;
                Core::FITKPoint newPoint = Core::RotateAroundAnyAxis(*point, *startPt, *axis, spacer*FITK_PI / 180 * i);
                int newID = disNodeList->addNode(newPoint.x(), newPoint.y(), newPoint.z());
                nodeIDs.insert(node->getNodeID(), newID);
            }
            //通过映射存入新节点
            QList<Acoustics::FITKAbstractSEASubSysWithNodes::SubSysNode> subSysNodeList = face->getNodes();
            QList<Acoustics::FITKAbstractSEASubSysWithNodes::SubSysNode> newSubSysNodeList;
            for (Acoustics::FITKAbstractSEASubSysWithNodes::SubSysNode subSysNode : subSysNodeList)
            {
                Acoustics::FITKAbstractSEASubSysWithNodes::SubSysNode newSubSysNode;
                newSubSysNode._id = nodeIDs[subSysNode._id];
                newSubSysNode._type = subSysNode._type;
                newSubSysNodeList.append(newSubSysNode);
            }
            //通过映射存入新三角形网格
            for (int i = 0; i < triang->getElementCount(); ++i)
            {
                Interface::FITKAbstractElement* element = triang->getElementAt(i);
                if (element == nullptr) return;
                Interface::FITKModelEnum::FITKEleType type = element->getEleType();
                Interface::FITKAbstractElement* newElement = Interface::FITKElementFactory::createElement(type);

                for (int j = 0; j < element->getNodeCount(); ++j)
                    newElement->setNodeID(j, nodeIDs[element->getNodeID(j)]);
                newTriang->appendElement(newElement);
            }
            newFace->setNodes(newSubSysNodeList);
            if (!newObj->updateGeoProp()) return;
            _objIDList.append(newObj->getDataObjectID());
        }
    }
    void GUIRectangularDialog::on_comboBox_Object_currentIndexChanged(int index)
    {
        _ui->comboBox_Model->clear();
        if (_ui->comboBox_Object->currentData().toInt() == _SEA_SUBSYSTEM_)
        {
            // SEA子系统
            _ui->comboBox_Model->addItem("Plate", _SEA_SHELL_);
            _ui->comboBox_Model->addItem("Beam", _SEA_BEAM_);
        }
        else if (_ui->comboBox_Object->currentData().toInt() == _FE_SUBSYSTEM_)
        {
            // FE子系统，暂时不做处理
        }
    }

    void GUIRectangularDialog::on_comboBox_Parameters_currentIndexChanged(int index)
    {
        if (_ui->comboBox_Parameters->currentData().toInt() == _LINE_SPACING_)
        {
            _ui->spinBox_Instances->setEnabled(true);
            _ui->lineEdit_Spacing->setEnabled(true);
            _ui->lineEdit_Length->setEnabled(false);
        }
        else if (_ui->comboBox_Parameters->currentData().toInt() == _LINE_LENGTH_)
        {
            _ui->spinBox_Instances->setEnabled(true);
            _ui->lineEdit_Spacing->setEnabled(false);
            _ui->lineEdit_Length->setEnabled(true);
        }
        else if (_ui->comboBox_Parameters->currentData().toInt() == _LINT_SPCAING_LENGTH_)
        {
            _ui->spinBox_Instances->setEnabled(false);
            _ui->lineEdit_Spacing->setEnabled(true);
            _ui->lineEdit_Length->setEnabled(true);
        }
    }

    void GUIRectangularDialog::on_comboBox_Parameters_2_currentIndexChanged(int index)
    {
        if (_ui->comboBox_Parameters_2->currentData().toInt() == _ARCED_SPACING_)
        {
            _ui->spinBox_Instances_2->setEnabled(true);
            _ui->lineEdit_Spacing_2->setEnabled(true);
            _ui->lineEdit_Angel->setEnabled(false);
        }
        else if (_ui->comboBox_Parameters_2->currentData().toInt() == _ARCED_LENGTH_)
        {
            _ui->spinBox_Instances_2->setEnabled(true);
            _ui->lineEdit_Spacing_2->setEnabled(false);
            _ui->lineEdit_Angel->setEnabled(true);
        }
        else if (_ui->comboBox_Parameters_2->currentData().toInt() == _ARCED_SPCAING_LENGTH_)
        {
            _ui->spinBox_Instances_2->setEnabled(false);
            _ui->lineEdit_Spacing_2->setEnabled(true);
            _ui->lineEdit_Angel->setEnabled(true);
        }
    }

    void GUIRectangularDialog::on_pushButtonPoint1_Pick_clicked()
    { 
        _flag = 1;
        enablePickSig(GUI::GUIPickInfo::POBJDiscNode, GUI::GUIPickInfo::PickMethod::PMSingle);
        
    }

    void GUIRectangularDialog::on_pushButtonPoint2_Pick_clicked()
    {
        _flag = 2;
        enablePickSig(GUI::GUIPickInfo::POBJDiscNode, GUI::GUIPickInfo::PickMethod::PMSingle);
    }

    void GUIRectangularDialog::on_pushButtonPoint3_Pick_clicked()
    {
        _flag = 3;
        enablePickSig(GUI::GUIPickInfo::POBJDiscNode, GUI::GUIPickInfo::PickMethod::PMSingle);
    }

    void GUIRectangularDialog::on_pushButtonPoint4_Pick_clicked()
    {
        _flag = 4;
        enablePickSig(GUI::GUIPickInfo::POBJDiscNode, GUI::GUIPickInfo::PickMethod::PMSingle);
    }
    void GUIRectangularDialog::on_pushButtonModel_Pick_clicked()
    {
        //拾取模型
        _flag = 5;
        if (_ui->comboBox_Object->currentData().toInt() == _SEA_SUBSYSTEM_)
        {
            //SEA模型
            if (_ui->comboBox_Model->currentData().toInt() == _SEA_SHELL_)
                enablePickSig(GUI::GUIPickInfo::POBJSEAShell, GUI::GUIPickInfo::PickMethod::PMSingle);
            else if (_ui->comboBox_Model->currentData().toInt() == _SEA_BEAM_)
                enablePickSig(GUI::GUIPickInfo::POBJSEABeam, GUI::GUIPickInfo::PickMethod::PMSingle);
        }
        else if (_ui->comboBox_Object->currentData().toInt() == _FE_SUBSYSTEM_)
        {
            //FE模型
        }
    }

    void GUIRectangularDialog::on_pushButton_OK_clicked()
    {
        if (_modelObjID == -1)
        {
            QMessageBox::warning(this, tr("warn"), tr("Please select a model"));
            return;
        }
        if (_oper == nullptr) return;
        if (_ui->comboBox_Object->currentData().toInt() == _SEA_SUBSYSTEM_)
        {
            if (_ui->tabWidget->currentIndex() == 0)
            {
                if ((_ui->lineEdit_Spacing->isEnabled()==true && _ui->lineEdit_Spacing->text().toDouble() <= 0) || 
                    (_ui->lineEdit_Spacing->isEnabled() == false && (_ui->lineEdit_Length->text().toDouble() / _ui->spinBox_Instances->text().toInt() <=0)))
                {
                    QMessageBox::warning(this, tr("warn"), tr("The interval is too small"));
                    return;
                }
                if (_ui->spinBox_Instances->isEnabled() == false && (_ui->lineEdit_Length->text().toDouble() / _ui->lineEdit_Spacing->text().toDouble() < 2))
                {
                    QMessageBox::warning(this, tr("warn"), tr("At least two models need to be generated"));
                    return;
                }
                if (_ui->Point_lineEditX->text().isEmpty() || _ui->Point_lineEditY->text().isEmpty() || _ui->Point_lineEditZ->text().isEmpty() ||
                    _ui->Point_lineEditX_2->text().isEmpty() || _ui->Point_lineEditY_2->text().isEmpty() || _ui->Point_lineEditZ_2->text().isEmpty())
                {
                    QMessageBox::warning(this, tr("warn"), tr("Please select a parameter direction"));
                    return;
                }
                this->rectangularLineSEAObj();
            }
            else if (_ui->tabWidget->currentIndex() == 1)
            {
                if (_ui->lineEdit_Spacing_2->text().toDouble() > 360 || _ui->lineEdit_Angel->text().toDouble() > 360)
                {
                    QMessageBox::warning(this, tr("warn"), tr("Please enter a reasonable number of degrees"));
                    return;
                }
                if ((_ui->lineEdit_Spacing_2->isEnabled() == true && _ui->lineEdit_Spacing_2->text().toDouble() <= 0) ||
                    (_ui->lineEdit_Spacing_2->isEnabled() == false && (_ui->lineEdit_Angel->text().toDouble() / _ui->spinBox_Instances_2->text().toInt() <= 0)))
                {
                    QMessageBox::warning(this, tr("warn"), tr("The interval is too small"));
                    return;
                }
                if (_ui->spinBox_Instances_2->isEnabled() == false && (_ui->lineEdit_Angel->text().toDouble() / _ui->lineEdit_Spacing_2->text().toDouble() < 2))
                {
                    QMessageBox::warning(this, tr("warn"), tr("At least two models need to be generated"));
                    return;
                }
                if (_ui->Point_lineEditX_3->text().isEmpty() || _ui->Point_lineEditY_3->text().isEmpty() || _ui->Point_lineEditZ_3->text().isEmpty() ||
                    _ui->Point_lineEditX_4->text().isEmpty() || _ui->Point_lineEditY_4->text().isEmpty() || _ui->Point_lineEditZ_4->text().isEmpty())
                {
                    QMessageBox::warning(this, tr("warn"), tr("Please select a reference axis"));
                    return;
                }
                this->rectangularArcedSEAObj ();
            }
        }
        _oper->setArgs("objID", _objIDList);
        this->accept();
    }

    void GUIRectangularDialog::on_pushButton_Cancel_clicked()
    {
        this->close();
    }
    void GUIRectangularDialog::enablePickSig(int pickObjType, int pickMethodType)
    {
        //获取拾取器，绑定拾取结束信号
        GraphData::PickedDataProvider* pickProvider = GraphData::PickedDataProvider::getInstance();
        //清除拾取对象所有的连接
        if (pickProvider != nullptr)
        {
            QObject::disconnect(pickProvider, SIGNAL(sig_pickedOver()), nullptr, nullptr);
            connect(pickProvider, &GraphData::PickedDataProvider::sig_pickedOver, this, &GUIRectangularDialog::pickFinishedOper);
        }
        GUI::GUIPickInfoStru pickInfo = GUI::GUIPickInfo::GetPickInfo();
        pickInfo._pickObjType = GUI::GUIPickInfo::PickObjType(pickObjType);
        pickInfo._pickMethod = GUI::GUIPickInfo::PickMethod(pickMethodType);
        //设置拾取方式
        GUI::GUIPickInfo::SetPickInfo(pickInfo);
    }
}


